package com.john.cloud.nacos.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: JohnCoding
 * @Description:
 * @date: 2020/7/6 10:12
 */
@SpringBootApplication
@EnableDiscoveryClient //注解表明是一个 Nacos 客户端，该注解是 Spring Cloud 提供的原生注解
public class ProviderApplication {

    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }

    @Value("${server.port}")
    private String port;

    @Value("${hello.name}")
    private String hello;

    @Autowired
    private ConfigurableApplicationContext applicationContext;

    @RestController
    public class EchoController {
        @GetMapping(value = "/echo/{message}")
        public String echo(@PathVariable String message) {
            return "Hello Nacos Discovery " + message  + " i am from port " + port;
        }

        @GetMapping("hello")
        public String hello(){
            return applicationContext.getEnvironment().getProperty("hello.name");
        }
    }

}
